using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.Events;
using StarterAssets;
public class SettingPanel : BasePanel
{
    [SerializeField] Button btnExitSetting;
    [SerializeField] Slider sliderMusic;
    [SerializeField] Toggle togMusic;
    [SerializeField] Toggle togSounds;
    [SerializeField] Slider sliderSounds;
    [SerializeField] MusicandSoundsSO musicAndSoundsSO;
    public override void Awake()
    {
        Init();
    }
    public override void Init()
    {
        sliderMusic.value = musicAndSoundsSO.MusicVolume;
        sliderSounds.value = musicAndSoundsSO.SoundsVolume;
        togMusic.isOn = musicAndSoundsSO.isMusicOpen;
        togSounds.isOn = musicAndSoundsSO.isSoundsOpen;
    }
    void Start()
    {
        btnExitSetting.onClick.AddListener(() =>
        {
            EventCenter.Instance.EventTrigger(E_EventType.BeginScene_btn_exitSetting);
            
            if (GameMgr.Instance.GetGameMode() == GameMgr.GameMode.Begin)
            {

            }
            else if (GameMgr.Instance.GetGameMode() == GameMgr.GameMode.Game)
            {
                StarterAssetsInputs.HideCursor();
            }
        });
        sliderMusic.onValueChanged.AddListener((value) =>
        {
            musicAndSoundsSO.MusicVolume = value;
        });
        sliderSounds.onValueChanged.AddListener((value) =>
        {
            musicAndSoundsSO.SoundsVolume = value;
        });
        togMusic.onValueChanged.AddListener((value) =>
        {
            musicAndSoundsSO.isMusicOpen = value;
        });
        togSounds.onValueChanged.AddListener((value) =>
        {
            musicAndSoundsSO.isSoundsOpen = value;
        });
    }

    
}
